package date20200923.com.kgc.contorlle;


import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import date20200923.com.kgc.entity.GoodDetail;
import date20200923.com.kgc.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.invoke.SerializedLambda;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class GoodContorlle {
    @Autowired
    private GoodService service;


    @RequestMapping("/listGoods")
    @ResponseBody
    public String listGoods(String sortId,int currentPage){
        List<GoodDetail> list = service.listGoods(sortId,currentPage);

        int totalCount = service.count(sortId);

        int totalPage = totalCount % 4 == 0 ? totalCount / 4 : totalCount / 4 + 1;

        Map<String,Object> map = new HashMap<>();

        map.put("list",list);
        map.put("totalPage",totalPage);

        return JSONObject.toJSONString(map);
    }
}
